{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据的制作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np \n",
    "import matplotlib.pyplot as plt "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "X=np.arange(0,10,0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2,\n",
       "       1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, 2.2, 2.3, 2.4, 2.5,\n",
       "       2.6, 2.7, 2.8, 2.9, 3. , 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8,\n",
       "       3.9, 4. , 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5. , 5.1,\n",
       "       5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6. , 6.1, 6.2, 6.3, 6.4,\n",
       "       6.5, 6.6, 6.7, 6.8, 6.9, 7. , 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7,\n",
       "       7.8, 7.9, 8. , 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9. ,\n",
       "       9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# GrandTruth\n",
    "GT=[10+3*x for x in X]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加一个抖动，加随机噪声\n",
    "# 正态分布都分布在均值中间\n",
    "Y=[np.random.normal(z, 3.6) for z in GT]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x11b669048>]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAGP9JREFUeJzt3X+sXPV55/H3xwMObn4sy+Uu60LuOlKjjaJEhc3dqF6q1sVtN9ugkCoSaqoWskTcVrvs4k3SgJHS0LrxpVIaHKktkVMCRmUTKCQbZGW7RW4tiHzF9hpYQuKulqVAoQY7DjTJaot7uU//mHOTYZh758yc3+d8XhK6M3PPzDxj7Od85/k+3+9RRGBmZs23qeoAzMwsH07oZmYt4YRuZtYSTuhmZi3hhG5m1hJO6GZmLeGEbmbWEk7oZmYt4YRuZtYSZ6Q5SNJTwPeAV4CViJiXdA5wF7ANeAq4PCJe3Oh1zj333Ni2bVuGcM3Muufo0aPfjojZccelSuiJn4mIbw/cvx44FBE3Sbo+uX/dRi+wbds2lpeXJ3hLMzOT9HSa47KUXC4DDiS3DwDvz/BaZmaWUdqEHsCfSToqaSF57LyIOJ7cfh44L/fozMwstbQll5+MiOck/TPgfkl/NfjLiAhJI7dtTE4ACwBzc3OZgjUzs/WlGqFHxHPJzxPAV4B3Ay9I2gqQ/DyxznP3R8R8RMzPzo6t6ZuZ2ZTGJnRJr5f0xrXbwM8DjwP3AVcmh10JfLWoIM3MbLw0JZfzgK9IWjv+v0bEn0r6S+BuSR8GngYuLy5MMzMbZ2xCj4gngR8f8f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8XrgJCf0vgbdKeoukzfQnTu6rOKZCSRL9muqxiPhM1fGUISJ2R8QFEbGN/v/jP4+I1o/YIuJ54G8k/cvkoZ3AtyoMqSzPAD8h6UeSv+876cBkcOI+4Mrk9pXAV/N64dpfJDoiViRdA/wP+jPhX4iIb1YcVtEuBn4V+IakR5PHboiIr1UYkxXnPwF3JgOWJ4F/X3E8hYuIhyTdAzxMv6vrEVq4alTSF4EdwLmSngU+CdwE3C3pw/R3n708t/fzSlEzs3ZoQsnFzMxScEI3M2sJJ3Qzs5ZwQjczawkndDOzlnBCNzNrCSd0M7OWcEI3M2uJfwQfkuZC5oO05wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x119558c50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(X, Y, 'k.')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<br><br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 解方程法求解最小二乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def lsm_func(x,y):\n",
    "    N=len(x)\n",
    "    sx=sum(x)\n",
    "    sy=sum(y)\n",
    "    sx2=sum(x**2)\n",
    "    sxy=sum(x*y)\n",
    "    G=np.mat([[N,sx],[sx,sx2]])\n",
    "    b=np.array([sy,sxy])\n",
    "    return np.linalg.solve(G,b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "a0,a1=lsm_func(X,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9.48590364561946 3.109983970166223\n"
     ]
    }
   ],
   "source": [
    "print(a0,a1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "Y_=[a0+a1*x for x in X]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5,1,'y=9.48590364561946+3.109983970166223x')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEICAYAAABPgw/pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xd4VGX2wPHvyYSQEHpdRCkWVFAsxIKii8KuivizolhZC9gLKBB0RRQhIEgTFUEpVmBVlFV0VRBxTWQNighiQUBFqZFeEkLO7497o0OcZG4yM5mS83meeTJz63tnJmfee+5731dUFWOMMfEvKdoFMMYYEx4W0I0xJkFYQDfGmARhAd0YYxKEBXRjjEkQFtCNMSZBWEA3xpgEYQHdAxFpJiJvishvIrJWRG7xuN4UEVEROdxvWksRmSsiW0RkvYhMEJFkv/kqIrtEZKf7eNZvXl0RmS4iG93H4BL7aykiH4rIbhH5RkS6+M3rISLfisg2d93pIlK7xPo9RGSFu/8fROSMAMc0yC2j/7aniUiBX5l3iojPb34NEXlKRDa7+1/oN+8st8zbRGRNgP2dJiL/E5EdIrJURDp6fa+9HlNZRKSNiOS6n9cWEflARNqUsfwd7vL5IjItwPzO7mez2z3uFn7zyvyeicgFIrLMfX+z/cshjkdF5Bf3vVwgIm395j8mIj+LyHYR+VFE7i/HtieW+GzzRWSH3/z6IjLbfY9/FJGr/OY1FZE5IvKr+/m0DPCedBGRz93114rI5X7zfO5x/ep+B74QkbruvJ4istg9prXuMSa786qLyHNueXaIyBIROa+in2vcUFV7BHkAHwJjgWrAccBvwFlB1ukIfAQocLjf9LnANCAV+AvwFXCX3/wDli+x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q7gNeB06LcpkqywYRaQrg/t0Yrg3HQ0D/DDhCRFqJSArOhZM5US5TRImI4ORUV6jq6GiXpzKo6kBVPVhVW+J8xvNVNeFrbKq6HvhZRI50J3UGvo5ikSrLT8CpIlLD/b53pgpcDHbNAXq6z3sCb4Zrw8nh2lCkqGqhiNwB/AfnSvgUVV0e5WJF2unAtcBXIrLEnXa/qs6NYplM5NwJvORWWFYB10e5PBGnqotE5FXgc5xWXV+QgN0AiMgrQCegoYisBR4ChgOzRORGnO7ELw/b/uzWf2OMSQzxkHIxxhjjgQV0Y4xJEBbQjTEmQVhAN8aYBGEB3RhjEoQFdGOMSRAW0I0xJkH8P4jd6YXipx8aAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11b690b38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(X,Y,'k.')\n",
    "plt.plot(X,Y_,'b')\n",
    "plt.plot(X,GT,'r')\n",
    "plt.title(\"y={}+{}x\".format(a0,a1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<br><br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 矩阵方法求解最小二乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "c=np.ones(len(X))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 偏置项在第一列\n",
    "G=np.mat(np.array([c, X]).T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 2)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "G.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "b=np.mat(Y).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[9.48590365],\n",
       "        [3.10998397]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(G.T*G).I*(G.T)*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9.48590364561946 3.109983970166223\n"
     ]
    }
   ],
   "source": [
    "print(a0,a1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4rc1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
